/* eslint-disable no-unneeded-ternary */
import React from 'react';
import {Spin, Card, Button, Row, Col, Form, Radio, Modal} from 'antd';
import PropTypes from 'prop-types';
import routes from './routes';
import {FORM_OPTIONS} from '../constants';
import {addApplyReport, getPartShipmentDetail} from './api';
import InputAmount from '../common/InputAmount';
import {isYesNo} from '../Enum';
import {injectIntl, language} from './intl';
import TextInput from 'Shared/components/TextInput';
import SearchInput from 'Shared/components/SearchInput';
import WrappedSelect from '../common/WrappedSelect';
import styles from './style.css';
import PartShipmentSelectPanel from './PartShipmentSelectPanel';
import Return from '../common/Return';
import LocalizeInputNumber from '../common/LocalizeInputNumber';
import WrappedDatePicker from '../common/WrappedDatePicker';
import {newOrUpdateOrderValidator} from './validator';
import qs from 'qs';
const FormItem = Form.Item;
const isYesNoToList = isYesNo.toList(language);
class AddPanel extends React.PureComponent {
    state = {
        loading: false,
        hasOperat: false,
        isValidate: false,
        data: {
            isLoadingCabinet: true,
            isMagnetic: 0,
            isChemical: 0,
            isPL: 0,
            isLoading: 0,
            isWarehousingAndAddress: 0,
            isExpressDocuments: 0,
            isRandomFiles: 0,
        },
        value: 1,
        showPartShipmentSelectPanel: false,
        cache: {}
    }
    componentDidMount() {
        const {partShipmentId} = qs.parse(this.props.history.location.search.replace('?', '')) || {};
        if(partShipmentId) {
            this.setState({loading: true});
            return getPartShipmentDetail(partShipmentId).then(res => {
                this.setState({loading: false});
                if(res.ok) {
                    const {partInvoiceCode, invoiceAmount, carrierId} = res.data;
                    this.setState({
                        data: Object.assign({}, this.state.data, {
                            partShipmentId,
                            partInvoiceCode,
                            invoiceFee: invoiceAmount,
                            carrierId,
                        }),
                        cache: res.data,
                        hasOperat: true,
                    });
                }
            });
        }
    }
    componentWillUnmount() {
        this.isunmount = true;
    }
    onChange = (value, name) => {
        const data = Object.assign({}, this.state.data, {
            [name]: value,
        });
        this.setState({
            data,
            hasOperat: true
        });
    }
    onClickOkOnPopconfirm = () => {
        this.props.onCancel();
    }
    onSubmit = () => {
        const data = this.state.data;
        const isValid = newOrUpdateOrderValidator(data);
        if(!isValid) {
            this.setState({
                isValidate: true
            });
            return;
        }
        const condition = {
            partShipmentId: data.partShipmentId,
            invoiceFee: data.invoiceFee,
            carrierId: data.carrierId,
            isMagnetic: data.isMagnetic === 1 ? true : false,
            isChemical: data.isChemical === 1 ? true : false,
            isPL: data.isPL === 1 ? true : false,
            isLoading: data.isLoading === 1 ? true : false,
            isWarehousingAndAddress: data.isWarehousingAndAddress === 1 ? true : false,
            isExpressDocuments: data.isExpressDocuments === 1 ? true : false,
            isRandomFiles: data.isRandomFiles === 1 ? true : false,
            isLoadingCabinet: data.isLoadingCabinet,
            loadingTime: data.loadingTime,
            loadingQuantity: data.loadingQuantity,
            isEnteringWarehouse: data.isEnteringWarehouse,
            deliveryTime: data.deliveryTime,
            inboundCode: data.inboundCode,
            isExpress: data.isExpress,
            expressPickupTime: data.expressPickupTime,
            expressCode: data.expressCode,
            detailCarrierId: data.detailCarrierId,
            isSelfMention: data.isSelfMention,
            collectPickupTime: data.collectPickupTime,
            shortContainerCount: data.shortContainerCount,
            standardContainerCount: data.standardContainerCount,
            highContainerCount: data.highContainerCount,
            consignee: data.consignee
        };
        this.setState({loading: true});
        addApplyReport(condition).then(res => {
            if(res.ok)
                this.props.successReturn();
            if(!this.isunmount)
                this.setState({loading: false});
        });
    }
    onRadioChange = e => {
        const cache = this.state.cache;
        const shortContainerCount = cache.shortContainerCount ? cache.shortContainerCount : 0;
        const standardContainerCount = cache.standardContainerCount ? cache.standardContainerCount : 0;
        const highContainerCount = cache.highContainerCount ? cache.highContainerCount : 0;
        
        if(e.target.value === 1)
            this.setState({
                data: Object.assign({}, this.state.data, {
                    isLoadingCabinet: true,
                    isEnteringWarehouse: undefined,
                    deliveryTime: undefined,
                    inboundCode: undefined,
                    isExpress: undefined,
                    expressPickupTime: undefined,
                    expressCode: undefined,
                    detailCarrierId: undefined,
                    isSelfMention: undefined,
                    collectPickupTime: undefined,
                    consignee: undefined,
                    loadingTime: cache.packingListCreatorTime,
                    loadingQuantity: shortContainerCount + standardContainerCount + highContainerCount,
                    shortContainerCount,
                    standardContainerCount,
                    highContainerCount
                }),
                value: e.target.value,
            });
        if(e.target.value === 2)
            this.setState({
                data: Object.assign({}, this.state.data, {
                    isLoadingCabinet: undefined,
                    loadingTime: undefined,
                    loadingQuantity: undefined,
                    isEnteringWarehouse: true,
                    isExpress: undefined,
                    expressPickupTime: undefined,
                    expressCode: undefined,
                    detailCarrierId: undefined,
                    isSelfMention: undefined,
                    collectPickupTime: undefined,
                    consignee: undefined,
                    shortContainerCount: undefined,
                    standardContainerCount: undefined,
                    highContainerCount: undefined,
                }),
                value: e.target.value,
            });
        if(e.target.value === 3)
            this.setState({
                data: Object.assign({}, this.state.data, {
                    isLoadingCabinet: undefined,
                    loadingTime: undefined,
                    loadingQuantity: undefined,
                    isEnteringWarehouse: undefined,
                    deliveryTime: undefined,
                    inboundCode: undefined,
                    isExpress: true,
                    isSelfMention: undefined,
                    collectPickupTime: undefined,
                    consignee: undefined,
                    shortContainerCount: undefined,
                    standardContainerCount: undefined,
                    highContainerCount: undefined,
                }),
                value: e.target.value,
            });
        if(e.target.value === 4)
            this.setState({
                data: Object.assign({}, this.state.data, {
                    isLoadingCabinet: undefined,
                    loadingTime: undefined,
                    loadingQuantity: undefined,
                    isEnteringWarehouse: undefined,
                    deliveryTime: undefined,
                    inboundCode: undefined,
                    isExpress: undefined,
                    expressPickupTime: undefined,
                    expressCode: undefined,
                    detailCarrierId: undefined,
                    isSelfMention: true,
                    shortContainerCount: undefined,
                    standardContainerCount: undefined,
                    highContainerCount: undefined,
                }),
                value: e.target.value,
            });
    };
    onClickSearchPartShipmentBtn = () => {
        this.setState({
            showPartShipmentSelectPanel: true
        });
    }
    onClosePartShipmentSelectPanel = () => {
        this.setState({showPartShipmentSelectPanel: false});
    }
    onChangePartShipment = records => {
        const shortContainerCount = records.shortContainerCount ? records.shortContainerCount : 0;
        const standardContainerCount = records.standardContainerCount ? records.standardContainerCount : 0;
        const highContainerCount = records.highContainerCount ? records.highContainerCount : 0;
        this.setState({
            data: Object.assign({}, this.state.data, {
                partShipmentId: records.partShipmentId,
                partInvoiceCode: records.partInvoiceCode,
                invoiceFee: records.invoiceAmount,
                carrierId: records.carrierId,
                loadingTime: records.packingListCreatorTime,
                loadingQuantity: shortContainerCount + standardContainerCount + highContainerCount,
                shortContainerCount,
                standardContainerCount,
                highContainerCount
            }),
            cache: records,
            hasOperat: true,
            showPartShipmentSelectPanel: false,
        });
    }
    onSelectPartShipment = records => {
        const {data} = this.state;
        const shortContainerCount = records.shortContainerCount ? records.shortContainerCount : 0;
        const standardContainerCount = records.standardContainerCount ? records.standardContainerCount : 0;
        const highContainerCount = records.highContainerCount ? records.highContainerCount : 0;
        if(data.partShipmentId && this.state.data.partShipmentId !== records.id)
            Modal.confirm({
                title: this.props.intl.formatMessage({
                    id: 'addPanel.message.switch',
                    defaultMessage: '提示'
                }),
                content: this.props.intl.formatMessage({
                    id: 'addPanel.message.switchDetails',
                    defaultMessage: '变更备件发运单，将会清空源单据数据，是否清空？'
                }),
                onOk: () => this.onChangePartShipment(records)
            });
        else
            this.setState({
                data: Object.assign({}, this.state.data, {
                    partShipmentId: records.partShipmentId,
                    partInvoiceCode: records.partInvoiceCode,
                    invoiceFee: records.invoiceAmount,
                    carrierId: records.carrierId,
                    loadingTime: records.packingListCreatorTime,
                    loadingQuantity: shortContainerCount + standardContainerCount + highContainerCount,
                    shortContainerCount,
                    standardContainerCount,
                    highContainerCount
                }),
                cache: records,
                hasOperat: true,
                showPartShipmentSelectPanel: false
            });
    }
    render() {
        const {formatMessage} = this.props.intl;
        const {data, isValidate, loading} = this.state;
        const {carrier} = this.props.initEnumData;
        data.loadingQuantity = (data.shortContainerCount ? data.shortContainerCount : 0) + (data.standardContainerCount ? data.standardContainerCount : 0) + (data.highContainerCount ? data.highContainerCount : 0);
        return (
            <div className="form-standard">
                <Spin spinning={this.state.loading}>
                    <Card title={formatMessage({
                        id: 'addPanel.column.common',
                        defaultMessage: '备件出运通知书信息'
                    })}>
                        <Form>
                            <Row>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={formatMessage({
                                            id: 'addPanel.form.partInvoiceCode',
                                            defaultMessage: '备件箱单发票编号'
                                        })}{...FORM_OPTIONS.item} validateStatus={isValidate && !data.partInvoiceCode ? 'error' : null} required>
                                        <SearchInput
                                            disabled={true}
                                            value={data.partInvoiceCode}
                                            onClickSearchBtn={this.onClickSearchPartShipmentBtn} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={formatMessage({
                                            id: 'addPanel.form.invoiceFee',
                                            defaultMessage: '报关金额'
                                        })} {...FORM_OPTIONS.item} validateStatus={isValidate && !data.invoiceFee ? 'error' : null} required>
                                        <InputAmount
                                            name="invoiceFee"
                                            value={data.invoiceFee}
                                            onChange={this.onChange} />
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={formatMessage({
                                            id: 'addPanel.operation.carrierId',
                                            defaultMessage: '货代名称'
                                        })} {...FORM_OPTIONS.item} validateStatus={isValidate && !data.carrierId ? 'error' : null} required>
                                        <WrappedSelect
                                            allowClear
                                            name="carrierId"
                                            options={carrier}
                                            value={data.carrierId}
                                            onChange={this.onChange}/>
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.form.isMagnetic',
                                        defaultMessage: '是否磁检'
                                    })}{...FORM_OPTIONS.item} validateStatus={isValidate && data.isMagnetic !== 0 && data.isMagnetic !== 1 ? 'error' : null} required>
                                        <WrappedSelect
                                            allowClear
                                            name="isMagnetic"
                                            options={isYesNoToList}
                                            value={data.isMagnetic}
                                            onChange={this.onChange}/>
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.form.isChemical',
                                        defaultMessage: '是否化工鉴定'
                                    })}{...FORM_OPTIONS.item} validateStatus={isValidate && data.isChemical !== 0 && data.isChemical !== 1 ? 'error' : null} required>
                                        <WrappedSelect
                                            allowClear
                                            name="isChemical"
                                            options={isYesNoToList}
                                            value={data.isChemical}
                                            onChange={this.onChange}/>
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.form.isPL',
                                        defaultMessage: '是否有装箱单'
                                    })}{...FORM_OPTIONS.item} validateStatus={isValidate && data.isPL !== 0 && data.isPL !== 1 ? 'error' : null} required>
                                        <WrappedSelect
                                            allowClear
                                            name="isPL"
                                            options={isYesNoToList}
                                            value={data.isPL}
                                            onChange={this.onChange}/>
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.form.isLoading',
                                        defaultMessage: '是否有装柜图'
                                    })}{...FORM_OPTIONS.item} validateStatus={isValidate && data.isLoading !== 0 && data.isLoading !== 1 ? 'error' : null} required>
                                        <WrappedSelect
                                            allowClear
                                            name="isLoading"
                                            options={isYesNoToList}
                                            value={data.isLoading}
                                            onChange={this.onChange}/>
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.form.isExpressDocuments',
                                        defaultMessage: '是否有快递面单'
                                    })}{...FORM_OPTIONS.item} validateStatus={isValidate && data.isExpressDocuments !== 0 && data.isExpressDocuments !== 1 ? 'error' : null} required>
                                        <WrappedSelect
                                            allowClear
                                            name="isExpressDocuments"
                                            options={isYesNoToList}
                                            value={data.isExpressDocuments}
                                            onChange={this.onChange}/>
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.form.isRandomFiles',
                                        defaultMessage: '是否有随机文件'
                                    })}{...FORM_OPTIONS.item} validateStatus={isValidate && data.isRandomFiles !== 0 && data.isRandomFiles !== 1 ? 'error' : null} required>
                                        <WrappedSelect
                                            allowClear
                                            name="isRandomFiles"
                                            options={isYesNoToList}
                                            value={data.isRandomFiles}
                                            onChange={this.onChange}/>
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem className={styles.multiLabel} label={formatMessage({
                                        id: 'addPanel.form.isWarehousingAndAddress',
                                        defaultMessage: '是否有进仓通知与地址'
                                    })}{...FORM_OPTIONS.item} validateStatus={isValidate && data.isWarehousingAndAddress !== 0 && data.isWarehousingAndAddress !== 1 ? 'error' : null} required>
                                        <WrappedSelect
                                            allowClear
                                            name="isWarehousingAndAddress"
                                            options={isYesNoToList}
                                            value={data.isWarehousingAndAddress}
                                            onChange={this.onChange}/>
                                    </FormItem>
                                </Col>
                            </Row>
                        </Form>
                    </Card>
                    <Card title={formatMessage({
                        id: 'addPanel.column.detailcommon',
                        defaultMessage: '备件出运通知书清单信息'
                    })}>
                        <Form>
                            <Row>
                                <Radio.Group onChange={this.onRadioChange} value={this.state.value}>
                                    <Radio value={1}>{formatMessage({
                                        id: 'addPanel.column.isLoadingCabinet',
                                        defaultMessage: '是否装柜'
                                    })}</Radio>
                                    <Radio value={2}>{formatMessage({
                                        id: 'addPanel.column.isEnteringWarehouse',
                                        defaultMessage: '是否进仓'
                                    })}</Radio>
                                    <Radio value={3}>{formatMessage({
                                        id: 'addPanel.column.isExpress',
                                        defaultMessage: '是否快递'
                                    })}</Radio>
                                    <Radio value={4}>{formatMessage({
                                        id: 'addPanel.column.isSelfMention',
                                        defaultMessage: '是否自提'
                                    })}</Radio>
                                </Radio.Group>
                            </Row>
                            <Row>
                                {this.state.value === 1 && <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.form.loadingTime',
                                        defaultMessage: '装柜时间'
                                    })}{...FORM_OPTIONS.item} validateStatus={isValidate && !data.loadingTime ? 'error' : null} required>
                                        <WrappedDatePicker
                                            allowClear
                                            name="loadingTime"
                                            value={data.loadingTime}
                                            onChange={this.onChange}/>
                                    </FormItem>
                                </Col>}
                                {this.state.value === 1 && <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.form.loadingQuantity',
                                        defaultMessage: '装柜数量'
                                    })}{...FORM_OPTIONS.item} validateStatus={isValidate && !data.loadingQuantity ? 'error' : null} required>
                                        <LocalizeInputNumber
                                            disabled
                                            min={0}
                                            name="loadingQuantity"
                                            value={data.loadingQuantity ? data.loadingQuantity : null}
                                            onChange={this.onChange}/>
                                    </FormItem>
                                </Col>}
                                {this.state.value === 1 && <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'updatePanel.form.shortContainerCount',
                                        defaultMessage: '20GP*数量'
                                    })}{...FORM_OPTIONS.item} validateStatus={isValidate && !data.shortContainerCount ? 'error' : null} required>
                                        <LocalizeInputNumber
                                            min={0}
                                            name="shortContainerCount"
                                            value={data.shortContainerCount}
                                            onChange={this.onChange}/>
                                    </FormItem>
                                </Col>}
                                {this.state.value === 1 && <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'updatePanel.form.standardContainerCount',
                                        defaultMessage: '40GP*数量'
                                    })}{...FORM_OPTIONS.item} validateStatus={isValidate && !data.standardContainerCount ? 'error' : null} required>
                                        <LocalizeInputNumber
                                            min={0}
                                            name="standardContainerCount"
                                            value={data.standardContainerCount}
                                            onChange={this.onChange}/>
                                    </FormItem>
                                </Col>}
                                {this.state.value === 1 && <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'updatePanel.form.highContainerCount',
                                        defaultMessage: '40HQ*数量'
                                    })}{...FORM_OPTIONS.item} validateStatus={isValidate && !data.highContainerCount ? 'error' : null} required>
                                        <LocalizeInputNumber
                                            min={0}
                                            name="highContainerCount"
                                            value={data.highContainerCount}
                                            onChange={this.onChange}/>
                                    </FormItem>
                                </Col>}
                                {this.state.value === 2 && <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.form.deliveryTime',
                                        defaultMessage: '要求送仓时间'
                                    })}{...FORM_OPTIONS.item} validateStatus={isValidate && !data.deliveryTime ? 'error' : null} required>
                                        <WrappedDatePicker
                                            allowClear
                                            name="deliveryTime"
                                            value={data.deliveryTime}
                                            onChange={this.onChange}/>
                                    </FormItem>
                                </Col>}
                                {this.state.value === 2 && <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.form.inboundCode',
                                        defaultMessage: '进仓编号'
                                    })}{...FORM_OPTIONS.item} validateStatus={isValidate && !data.inboundCode ? 'error' : null} required>
                                        <TextInput
                                            name="inboundCode"
                                            value={data.inboundCode}
                                            onChange={this.onChange}/>
                                    </FormItem>
                                </Col>}
                                {this.state.value === 3 && <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.form.expressPickupTime',
                                        defaultMessage: '快递取货时间'
                                    })}{...FORM_OPTIONS.item} validateStatus={isValidate && !data.expressPickupTime ? 'error' : null} required>
                                        <WrappedDatePicker
                                            allowClear
                                            name="expressPickupTime"
                                            value={data.expressPickupTime}
                                            onChange={this.onChange}/>
                                    </FormItem>
                                </Col>}
                                {this.state.value === 3 && <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.form.detailCarrierId',
                                        defaultMessage: '货代名称'
                                    })}{...FORM_OPTIONS.item} validateStatus={isValidate && !data.detailCarrierId ? 'error' : null} required>
                                        <WrappedSelect
                                            allowClear
                                            name="detailCarrierId"
                                            options={carrier}
                                            value={data.detailCarrierId}
                                            onChange={this.onChange}/>
                                    </FormItem>
                                </Col>}
                                {this.state.value === 3 && <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.form.expressCode',
                                        defaultMessage: '面单号'
                                    })}{...FORM_OPTIONS.item} validateStatus={isValidate && !data.expressCode ? 'error' : null} required>
                                        <TextInput
                                            name="expressCode"
                                            value={data.expressCode}
                                            onChange={this.onChange}/>
                                    </FormItem>
                                </Col>}
                                {this.state.value === 4 && <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.form.collectPickupTime',
                                        defaultMessage: '自提取货时间'
                                    })}{...FORM_OPTIONS.item} validateStatus={isValidate && !data.collectPickupTime ? 'error' : null} required>
                                        <WrappedDatePicker
                                            allowClear
                                            name="collectPickupTime"
                                            value={data.collectPickupTime}
                                            onChange={this.onChange}/>
                                    </FormItem>
                                </Col>}
                                {this.state.value === 4 && <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'addPanel.form.consignee',
                                        defaultMessage: '提货人'
                                    })}{...FORM_OPTIONS.item} validateStatus={isValidate && !data.consignee ? 'error' : null} required>
                                        <TextInput
                                            name="consignee"
                                            value={data.consignee}
                                            onChange={this.onChange}/>
                                    </FormItem>
                                </Col>}
                            </Row>
                        </Form>
                    </Card>
                    <Card className={styles.optionBtn}>
                        <Button
                            type="primary"
                            onClick={this.onSubmit}
                            loading={loading}>
                            {formatMessage({
                                id: 'addPanel.operation.onSave',
                                defaultMessage: '保存'
                            })}
                        </Button>
                    </Card>
                    {
                        this.state.showPartShipmentSelectPanel &&
                    <PartShipmentSelectPanel
                        selectKey={data.partShipmentId}
                        onCancel={this.onClosePartShipmentSelectPanel}
                        onSelect={this.onSelectPartShipment} />
                    }
                </Spin>
                <div className="page-toolbar">
                    <Return
                        disabled={this.state.loading}
                        onConfirm={this.onClickOkOnPopconfirm}
                        showWarning={this.state.hasOperat} />
                </div>
            </div>
        );
    }
}

AddPanel.propTypes = {
    initEnumData: PropTypes.object.isRequired,
    successReturn: PropTypes.func.isRequired,
    onCancel: PropTypes.func.isRequired,
    history: PropTypes.object,
    id: PropTypes.string,
    intl: PropTypes.object,
};

import {connect} from 'react-redux';
import {
    tableSearch
} from './actions';
import {createSelector} from 'reselect';
const getinitEnumData = createSelector(
    state => state.getIn(['page', 'domainData', 'init']),
    init => {
        const initData = init.toJS();
        const carrier = initData.carrier ? initData.carrier.map(item => ({
            text: item.name,
            value: item.id
        })) : [];
        return {
            carrier
        };
    }
);
const mapStateToProps = state => ({
    initEnumData: getinitEnumData(state),
});
const mapDispatchToProps = (dispatch, props) => ({
    successReturn: () => {
        dispatch(tableSearch());
        props.history.push(routes.query.url());
    },
    onCancel: () => {
        props.history.push(routes.query.url());
    },
});
export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(AddPanel));
